package edu.whut.method;
/*
 * 查找元素在数组中的索引,包括重复
 */
public class test01 {
    public static void main(String[] args) {
        int[] arr={1,8,1,9,7,1};

        int[] result = findIndex(0,arr);
        if(result.length==0){
            System.out.println("不存在");
        }else {
            for (int i = 0; i < result.length; i++) {
                System.out.println(result[i]);
            }
        }
    }
    public static int[] findIndex(int num,int[] arr){
        //先统计出现的个数
        int count=0;
        for (int i = 0; i < arr.length; i++) {
            if(num==arr[i]){
                count++;
            }
        }
        int[] result = new int[count];

        int k =0;
        for (int i = 0; i < arr.length; i++) {
            if(num == arr[i]){
                result[k++] = i;

            }
        }
        return result;

    }
}
